package cn.tedu.tmall.admin.content.controller;

import cn.tedu.tmall.admin.content.pojo.param.CategoryAddNewParam;
import cn.tedu.tmall.admin.content.pojo.vo.CategoryStandardVO;
import cn.tedu.tmall.admin.content.service.ICategoryService;
import cn.tedu.tmall.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/categories")
@Api(tags = "01. 类别管理")
@Validated
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @PostMapping("/add-new")
    @ApiOperation("新增类别")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid CategoryAddNewParam categoryAddNewParam) {
        categoryService.addNew(categoryAddNewParam);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID获取类别详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    public JsonResult getStandardById(@Range(min = 1, message = "根据ID获取类别详情失败，请提交有效的ID值！")
                                      @PathVariable Long id) {
        CategoryStandardVO queryResult = categoryService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }
}
